package com.jwaoo.mobile;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.baidu.mobstat.StatService;
import com.dx.as.JWCache;
import com.dx.as.permission.MPermission;
import com.dx.as.permission.annotation.OnMPermissionDenied;
import com.dx.as.permission.annotation.OnMPermissionGranted;
import com.dx.as.permission.annotation.OnMPermissionNeverAskAgain;
import com.jwaoo.mobile.view.login.LoginActivity;
import com.jwaoo.mobile.view.main.MainActivity;

/**
 * Created by jwaoo on 2017/6/12.
 */

public class SplashActivity extends Activity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (ApplicationHelper.lastCls == null){
//            setContentView(R.layout.activity_splash);
            StatService.start(this);
            toMainView();
        }else{
            Intent intent = new Intent(this,ApplicationHelper.lastCls);
            intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
            startActivity(intent);
            finish();
            return;
        }
    }

    private void toMainView(){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent mainIntent = new Intent();
                if (JWCache.isLogin()){
                    mainIntent.setClass(SplashActivity.this, MainActivity.class);
                }else {
                    mainIntent.setClass(SplashActivity.this, LoginActivity.class);
                }
                startActivity(mainIntent);
                finish();
            }
        },1500);
    }
}
